package com.origin.baselibrary.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.origin.netlibrary.NetStack
import com.origin.utils.log.LogUtils
import kotlinx.coroutines.*

open class BaseViewModel : ViewModel() {
    override fun onCleared() {
        super.onCleared()
        LogUtils._e("BaseViewModel onCleared")
        NetStack.clearByVm(viewModelScope)
    }

    fun viewModelSuspend(block: suspend CoroutineScope.() -> Unit) {
        viewModelScope.launch {
            block.invoke(this);
        }
    }

}